package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;
import com.wgts.wgts.dagger.ComponentHolder;
import com.wgts.wgts.dagger.component.DaggerUpgradeShopKeeperActivityComponent;
import com.wgts.wgts.dagger.module.UpgradeShopKeeperActivityModule;
import com.wgts.wgts.mvp.presenter.IUpgradeShopKeeperFragmentPresenter;
import com.wgts.wgts.mvp.view.IUpgradeShopKeeperFragmentView;
import com.wgts.wgts.mvp.view.activity.webactivity.WebActivity;
import com.wgts.wgts.netmodle.resp.SearchShopResultEntity;
import com.wgts.wgts.netmodle.resp.WgtsProductListEntity;
import com.wgts.wgts.tools.AppInfor;
import com.wgts.wgts.tools.CustomImageView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UpgradeShopKeeperActivity extends BaseActivity implements IUpgradeShopKeeperFragmentView {


    @Inject
    IUpgradeShopKeeperFragmentPresenter presenter;
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.linear_title)
    LinearLayout linearTitle;
    @BindView(R.id.img_head)
    ImageView imgHead;
    @BindView(R.id.recycle_view)
    RecyclerView recycleView;
    @BindView(R.id.scroll_view)
    NestedScrollView scrollView;


    private SearchShopResultEntity entitys;


    @Override
    public void init() {
        DaggerUpgradeShopKeeperActivityComponent
                .builder()
                .appComponent(ComponentHolder.getInstance().getAppComponent())
                .upgradeShopKeeperActivityModule(new UpgradeShopKeeperActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.upgrade_shop_keeper_fragment);
        ButterKnife.bind(this);

        initView();
    }


    private void initView() {

        //imgDialog.setVisibility(View.GONE);

        imgBack.setVisibility(View.VISIBLE);
        if (AppInfor.getInstance().getUserState() > 1) {
            CustomImageView.getInstance().customImage(this, imgHead, 500 / (double) 750);
            tvTitle.setText("邀请有礼");
        } else {
            CustomImageView.getInstance().customImage(this, imgHead, 586 / (double) 750);
            tvTitle.setText("升级店主");
        }
        linearTitle.setBackgroundColor(Color.argb(0, 255, 255, 255));
        tvTitle.setTextColor(Color.argb(0, 0, 0, 0));


        final ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(InvitationRecordFragment.getInstance(0));
        fragments.add(InvitationRecordFragment.getInstance(1));

//        viewPageReward.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
//            @Override
//            public Fragment getItem(int i) {
//                return fragments.get(i);
//            }
//
//            @Override
//            public int getCount() {
//                return fragments.size();
//            }
//        });
//
//        viewPageReward.setScanScroll(false);


        linearTitle.setBackgroundColor(Color.argb(0, 255, 255, 255));
        tvTitle.setTextColor(Color.argb(0, 0, 0, 0));


        scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

            int alpha = 0;
            int count = 0;
            float scale = 0;

            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (scrollY <= 375) {
                    scale = (float) scrollY / 375;
                    alpha = (int) (255 * scale);
                    // 随着滑动距离改变透明度
                    // Log.e("al=","="+alpha);
                    linearTitle.setBackgroundColor(Color.argb(alpha, 255, 255, 255));
                    tvTitle.setTextColor(Color.argb(alpha, 0, 0, 0));
                } else {
                    if (alpha < 255) {
                        Log.e("执行次数", "=" + (++count));
                        // 防止频繁重复设置相同的值影响性能
                        alpha = 255;
                        linearTitle.setBackgroundColor(Color.argb(alpha, 255, 255, 255));
                        tvTitle.setTextColor(Color.argb(alpha, 0, 0, 0));
                    }
                }
            }


        });

    }


    @Override
    public void productResult(List<WgtsProductListEntity> entitys) {

    }

    @Override
    public void shopKeepPhone(String shopKeepPhone) {

    }


    @Override
    public void onError(int status, String msg) {

    }
}
